(function () {

    "use strict";

    var api = {
        getListsUrl: "/api/ticket/getTicketList",
        getSummary: "/api/ticket/getSummary"
    };

    sm.controller('wx-center-ticket-index-controller', ['$scope', '$http', '$sce', function ($scope, $http, $sce){

        $scope.type = 'nouse';
        $scope.nowType = 'nouse';
        $scope.lists = [];
        $scope.tips = false;
        $scope.summary = {
            nouse: 0,
            used: 0,
            expires: 0
        };

        /**
         * 获取列表
         */
        $scope.getLists = function (type) {

            if (!type) {
                type = 'nouse'
            }

            if (type != 'nouse' && type != 'used' && type != 'expires') {
                return false;
            }

            $scope.nowType = type;

            $http.get(api.getListsUrl, {
                params: {
                    type: type,
                    page: 1
                }
            }).success(function (res) {
                if (res.state) {
                    $scope.lists = res.data
                    angular.forEach($scope.lists, function (val) {
                        val["description"] = $sce.trustAsHtml(val['description']);
                        val["detail"] = false;
                    });
                }
            });

        };

        $scope.getSummary = function () {
            $http.get(api.getSummary).success(function (res) {
                if (res.state) {

                    if (res.data.noget > 0) {
                        $scope.tips = true;
                    }

                    $scope.summary = {
                        nouse: res.data.nouse,
                        used: res.data.used,
                        expires: res.data.expires
                    }
                }
            });
        };

        $scope.showDetail = function() {

        };


        // 获取不同类型优惠券数量
        $scope.getSummary();
        $scope.getLists('nouse');

        $scope.getTicket = function () {
            location.href="/center/getTicket"
        }


    }]);
})();

